package com.hjm.system.controller.suser;


import com.hjm.common.core.constants.HttpConstants;
import com.hjm.common.core.domain.Result;
import com.hjm.common.core.controller.BaseController;
import com.hjm.system.domain.suser.dto.LoginUserDTO;
import com.hjm.common.core.domain.vo.LoginUserVO;
import com.hjm.system.service.suser.impl.SysUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys")
public class SysUserController extends BaseController {

    @Autowired
    SysUserServiceImpl sysUserService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginUserDTO loginUserDTO) {

        return sysUserService.login(loginUserDTO);

    }

    @GetMapping("/info")
    public Result<LoginUserVO> getSysUser(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }

    @PostMapping("/add")
    public Result<Void> addSysUser(@RequestBody LoginUserDTO loginUserDTO) {
        return toResult(sysUserService.addSysUser(loginUserDTO));
    }
/*    @PostMapping("/add")
    public Result<Void> addSysUser() {
        LoginUserDTO loginUserDTO = new LoginUserDTO();
        return toResult(sysUserService.addSysUser(loginUserDTO));
    }*/

    @DeleteMapping("/exit")
    public Result<Void> exit(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toResult(sysUserService.exit(token));
    }
}
